// Fill out your copyright notice in the Description page of Project Settings.

#include "Isalong2.h"
#include "CPlayerCharacter.h"
#include "CPlayerCharacterController.h"
#include "InteractItem.h"
#include "MainInventoryUI.h"




TArray<FItemUIBlock> UMainInventoryUI::GetBagDatas()
{
	TArray<FItemUIBlock> result;
	ACPlayerCharacter* Character = Cast<ACPlayerCharacter>(ACPlayerCharacterController::_localPlayerController->GetPawn());
	TArray<Item> frenData = Character->GetBagDatas();
	for (int i = 0; i < frenData.Num(); i++)
	{
		// split the hand ____ no use
		if (frenData[i]._itemID==ITEMTYPE_hand)
		{
			continue;
		}
		FItemUIBlock fiub;
		fiub._id = frenData[i]._itemID;
		fiub._num = frenData[i]._itemCount;
		fiub._data = *ItemType::GetItemDisplayByID(fiub._id);
		result.Add(fiub);
	}
	return result;
}

FString UMainInventoryUI::GetItemFStringNameByID(int32 id)
{
	return ItemType::GetItemFStringNameByID(id);
}

FItemDisplay UMainInventoryUI::GetItemDisplayDataById(int32 id)
{
	return *ItemType::GetItemDisplayByID(id);
}

void UMainInventoryUI::RemoveFromCharacterBag(int32 id, int32 count)
{
	ACPlayerCharacter* Character = Cast<ACPlayerCharacter>(ACPlayerCharacterController::_localPlayerController->GetPawn());
	Character->RemoveItemFromBags(id, count);
}

void UMainInventoryUI::AddToCharacterBag(int32 id, int32 count)
{
	ACPlayerCharacter* Character = Cast<ACPlayerCharacter>(ACPlayerCharacterController::_localPlayerController->GetPawn());
	Character->AddItemToBags(id, count);
}

void UMainInventoryUI::DropItemFromCharacterBag(int32 id, int32 count)
{
	ACPlayerCharacter* Character = Cast<ACPlayerCharacter>(ACPlayerCharacterController::_localPlayerController->GetPawn());
	Character->DropItemFromBags(id, count);
}
